﻿using AutoMapper;
using EFEntity;
using Iservices;
using Microsoft.EntityFrameworkCore;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Services
{
    public class Config_majorService : IConfig_majorService
    {
        private readonly MyDbContext myDbContext;
      
      
      	 private readonly IMapper mapper;

        public Config_majorService(IMapper mapper,MyDbContext myDbContext)
        {
            
            this.myDbContext = myDbContext;
            this.mapper = mapper;
        }
        public async Task<int> AddAsync(Config_major cm)
        {
            
            EConfig_major e = mapper.Map<EConfig_major>(cm);
            myDbContext.Add(e);
            int result = await myDbContext.SaveChangesAsync();
            return result;
        }

        public async Task<int> DeleteAsync(int id)
        {
            EConfig_major t = new EConfig_major();
            t = myDbContext.Econfig.Find(id);
            myDbContext.Econfig.Remove(t);
            int result = await myDbContext.SaveChangesAsync();
            return result;
        }

        public async Task<List<Config_major>> SelectAsync()
        {
            List<EConfig_major> list = new List<EConfig_major>();
            await Task.Run(() => {
                list = myDbContext.Econfig.ToList();
            });
            List<Config_major> list2 = mapper.Map<List<Config_major>>(list);
        
            return list2;
        }
    }
}
